<template>
  <div class="contract">
    <van-nav-bar class="contract-bar" title="发起签约" :border="false" />
    <div class="below">
      <span @click="belowShow = true">{{ orgName }}</span>
      <i class="up-triangle" v-if="belowShow"></i>
      <i class="below-triangle" v-else></i>
    </div>
    <!-- 上传合同 -->
    <div class="contract-file">
      <van-uploader :after-read="afterRead" accept=".pdf">
        <van-cell icon="back-top" center title="上传签约文件" is-link />
      </van-uploader>
      <van-uploader :after-read="afterRead" accept=".pdf">
        <van-cell icon="apps-o" center title="选择本地文件" is-link />
      </van-uploader>
    </div>
    <!-- 合同摸版 -->
    <van-tabs
      class="tabs-title"
      v-model="active"
      swipeable
      animated
      :ellipsis="false"
      title-active-color="#2489f2"
    >
      <van-tab title="全部模板">
        <my-business />
      </van-tab>
      <van-tab
        :title="item.businessTypeName"
        v-for="(item, index) in business"
        :key="index"
      >
        <my-business :businessType="item.businessType" />
      </van-tab>
    </van-tabs>
    <!-- 底部弹出层 -->
    <van-popup
      v-model="belowShow"
      position="bottom"
      :style="{ height: '30%' }"
      :close-on-click-overlay="false"
    >
      <div
        class="below-show-name"
        v-for="(item, index) in tyleName"
        :key="index"
        @click="selectOrganization(item)"
      >
        {{ item }}
      </div>
      <van-button
        class="btn-fixed"
        type="default"
        block
        @click="belowShow = false"
        >取消</van-button
      >
    </van-popup>
  </div>
</template>

<script>
import { businessTyle, fileUpload } from '@/api/user'
import MyBusiness from './components/business-list'
export default {
  data() {
    return {
      // 合同类型
      active: 0,
      business: [],
      belowShow: false,
      orgName: '',
      tyleName: ['张三', '北京华信云盛科技有限公司', '北京华信云盛科技', '李四']
    }
  },
  created() {
    this.list()
    this.orgName = this.$store.state.userName.orgName
  },
  mounted() {},
  methods: {
    async list() {
      try {
        const { data: res } = await businessTyle()
        if (res.code !== '0') {
          return this.$toast.fail('数据获取失败')
        }
        this.business = res.data
      } catch (error) {
        console.log(error)
      }
    },
    // 下拉框选择事件
    addDropdown(value) {
      this.contract = this.option1[value].text
    },
    // 文件上传
    async afterRead(file) {
      this.$toast.loading({
        message: '上传中',
        forbidClick: true
      })
      const formData = new FormData()
      formData.append('file', file.file)
      try {
        const { data: res } = await fileUpload(formData)
        if (res.code !== '0') {
          return this.$toast.fail('上传失败，请重试！')
        }
        this.$toast.success('上传成功')
        const fileList = {
          fileType: '1',
          fileName: res.data.fileName,
          filePath: res.data.filePath,
          filePages: res.data.filePages
        }
        this.$store.commit('setFileList', fileList)
        this.$router.push('/ContractInformation')
      } catch (error) {
        console.log(error)
      }
    },
    // 选泽机构
    selectOrganization(value) {
      this.orgName = value
      this.belowShow = false
    }
  },
  components: {
    MyBusiness
  }
}
</script>

<style scoped lang="less">
.contract {
  background-color: #f8f8f8;
  height: 100vh;
  box-sizing: border-box;
  overflow: hidden;
  padding-bottom: 180px;
  .contract-bar {
    height: 88px;
    box-sizing: border-box;
    overflow: hidden;
    /deep/.van-ellipsis {
      font-size: 34px;
      font-weight: bold;
    }
  }
  .below {
    height: 80px;
    padding-left: 41px;
    display: flex;
    align-items: center;
    background-color: #fff;
    span {
      font-size: 28px;
      color: #666666;
    }
    .below-triangle {
      margin-left: 12px;
      width: 0;
      height: 0;
      border-right: 10px solid transparent;
      border-left: 10px solid transparent;
      border-top: 10px solid #666666;
    }
    .up-triangle {
      margin-left: 12px;
      width: 0;
      height: 0;
      border-right: 10px solid transparent;
      border-left: 10px solid transparent;
      border-bottom: 10px solid #666666;
    }
  }
  // 上传文件
  .contract-file {
    display: flex;
    box-sizing: border-box;
    flex-direction: column;
    height: 316px;
    padding: 20px 40px 30px;
    /deep/.van-uploader__input-wrapper {
      width: 100%;
    }
    .van-uploader {
      margin-bottom: 20px;
    }
    .van-cell {
      height: 128px;
      font-size: 30px;
      // 图标样式
      .van-cell__left-icon {
        margin-right: 25px;
        width: 40px;
        height: 40px;
        line-height: 40px;
        text-align: center;
        background-color: #2489f2;
        color: #fff;
        border-radius: 10px;
      }
    }
  }
  //
  /deep/.tabs-title {
    .van-tabs__wrap {
      height: 80px;
    }
    .van-tab {
      border-bottom: 1px solid #e4e4e4;
      width: 33.33%;
    }
    .van-tabs__line {
      width: 40px;
      height: 5px;
      background-color: #2489f2;
    }
    .van-tabs__nav--complete {
      padding-left: 0;
      padding-right: 0;
    }
    .complate-content {
      height: 180px;
      display: flex;
      align-items: center;
      background-color: #fff;
      img {
        width: 98px;
        height: 124px;
        border: 1px solid #e4e4e4;
        margin: 0 27px 0 40px;
      }
      div {
        height: 100%;
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: space-between;
        border-bottom: 1px solid #e4e4e4;
        span {
          font-size: 30px;
        }
        button {
          width: 92px;
          height: 50px;
          background-color: #2489f2;
          border-radius: 6px;
          font-size: 24px;
          color: #fff;
          border-width: 0px;
          margin-right: 40px;
        }
      }
    }
  }
  .van-popup {
    padding-bottom: 130px;
    box-sizing: border-box;
    background-color: #f8f8f8;
    .below-show-name {
      height: 110px;
      font-size: 30px;
      text-align: center;
      line-height: 110px;
      border-top: 1px solid #e4e4e4;
      background-color: #fff;
    }
    .btn-fixed {
      height: 110px;
      position: fixed;
      bottom: 0;
      left: 0;
      border-width: 0;
    }
  }
}
</style>
